package com.team.employment.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.team.employment.model.entity.CompanyStatutory;
import com.team.employment.model.entity.StatutoryInfo;
import com.team.employment.web.admin.dto.StatutoryQueryDto;
import com.team.employment.web.admin.mapper.CompanyStatutoryMapper;
import com.team.employment.web.admin.service.StatutoryInfoService;

import com.team.employment.web.admin.mapper.StatutoryInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 陈钰儿
* @description 针对表【statutory_info(法定人信息表(全必填))】的数据库操作Service实现
* @createDate 2025-04-11 15:49:27
*/
@Service
public class StatutoryInfoServiceImpl extends ServiceImpl<StatutoryInfoMapper, StatutoryInfo>
    implements StatutoryInfoService{


    @Autowired
    private StatutoryInfoMapper statutoryInfoMapper;

    @Autowired
    private CompanyStatutoryMapper companyStatutoryMapper;

    @Override
    public StatutoryInfo getStatutoryById(Long id) {
        LambdaQueryWrapper<CompanyStatutory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CompanyStatutory::getCompanyId,id);
        CompanyStatutory companyStatutory = companyStatutoryMapper.selectOne(lambdaQueryWrapper);

        LambdaQueryWrapper<StatutoryInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StatutoryInfo::getId,companyStatutory.getStatutoryId());
        StatutoryInfo statutoryInfo = statutoryInfoMapper.selectOne(wrapper);
        return statutoryInfo;
    }

    @Override
    public IPage<StatutoryInfo> queryByPage(StatutoryQueryDto queryDto, Page<StatutoryInfo> page) {
        return statutoryInfoMapper.selectByPage(page, queryDto);
    }

    @Override
    public void removeStatutoryById(Long statutoryId) {
        // 调用Mapper执行组合SQL操作
        // 先逻辑删除法定人
        companyStatutoryMapper.logicDeleteStatutory(statutoryId);
        // 再封禁关联公司
        companyStatutoryMapper.deleteStatutoryWithCompanyUpdate(statutoryId);
        //最后逻辑删除关联表信息
        companyStatutoryMapper.deleteCompanyStatus(statutoryId);
    }

}




